function static_items()

	Apple = { name = "apple", desc="A small red apple",
		value = 1, it = "thrown", it2 = "fruit", x = 0, y = 0, hand = "none",
		image = apple_img, explored = false }

	Hatchet = { name = "hatchet", desc="for overgrowth",
		value = 1, it = "melee", it2 = "metal", x = 0, y = 0, hand = "left",
		image = axe_img	, uses = 10, explored = false	}

	Pistol = { name = "pistol", desc="for shoot",
		value = 10, it = "gun", it2 = "metal", x = 0, y = 0, hand = "right",
		image = pistol_img, damage = 10, ammo_req = 1, speed = 4, explored = false	}

	Grenade = { name = "grenade", desc="for boom",
		value = 5, it = "grenade", it2 = "metal", x = 0, y = 0, hand = "none",
		image = grenade_img, damage = 20, radius = 1, explored = false }



end

function static_item_generator(item)

	local r = 0

	for i = 1, #item do


		if type(item[i]) == "number" then



		end

	end



end

function generate_random_grenade(Grenade)

	local r = RNG:random(100)
	local nr = ""
	local d = RNG:random(100)
	local nd = ""
	print("r : ", r)
	print("d : ", d)
	if r > 50 then
		Grenade.radius = 1
		nr = "puny "
	elseif r < 51 and r > 25 then
		Grenade.radius = 2
		nr = "mild "
	elseif r < 26 and r > 8 then
		Grenade.radius = 3
		nr = "loaded "
	else
		Grenade.radius = 4
		nr = "spicy "
	end

	if d > 50 then
		Grenade.damage = 10
		nd = "weak "
	elseif d < 51 and d > 25 then
		Grenade.damage = 15
		nd = "typical "
	elseif d < 26 and d > 8 then
		Grenade.damage = 20
		nd = "saucy "
	else
		Grenade.damage = 30
		nd = "delish "
	end

	local nn = append_strings(nd, nr)
	Grenade.name = append_strings(nn, "grenade")

	return Grenade



end

function give_item(item, recipient)

	table.insert(recipient.inventory, item)


end

function hatchet_chop(dir, map, player)
	-- create floor map

	local pX = player.x/tile_size
	local pY = player.y/tile_size

	if dir == "up" then
		print("inside dir up")
		if pY-1 ~= 1 then
			print("inside py")
			if map[pY-1][pX].type == "wall" then
				map[pY-1][pX].type = "floor"

				local str = "You chop the tree"
				printc(str)

				tree_spawn(pX*tile_size, (pY-1)*tile_size, data.player.local_map.items)

			else

			end
		end
	elseif dir == "down" then
		if pY+1 ~= grid_size then
			if map[pY+1][pX].type == "wall" then
				map[pY+1][pX].type = "floor"

				local str = "You chop the tree"
				printc(str)
				tree_spawn( pX*tile_size,(pY+1)*tile_size,data.player.local_map.items)
			else

			end
		end
	elseif dir == "right" then
		if pX+1 ~= grid_size then
			if map[pY][pX+1].type == "wall" then
				map[pY][pX+1].type = "floor"
				local str = "You chop the tree"
				printc(str)
				tree_spawn((pX+1)*tile_size,pY*tile_size, data.player.local_map.items)
			else

			end
		end
	elseif dir == "left" then
		if pX-1 ~= 1 then
			if map[pY][pX-1].type == "wall" then

				map[pY][pX-1].type = "floor"
				local str = "You chop the tree"
				printc(str)

				tree_spawn((pX-1)*tile_size, pY*tile_size, data.player.local_map.items)
			else

			end
		end
	end

	for i = 1, #local_map.tiles do
		if local_map.tiles[i].x == player.x and local_map.tiles[i].y == player.y
			and local_map.tiles[i].type == "wall" then
			local_map.tiles[i].type = "floor"
			local_map.tiles[i].image = tree_stump_img

		end

	end

	--rebuild_tiles(map,local_map.tiles)

end

function shoot_gun(x,y, gun) -- bullet spawn
	print("shooting gun")
	if data.player.bullets >= gun.ammo_req then
		Bullet = { name="bullet", desc="for killing", speed_mod = 1, speed = gun.speed,
			value = 1, it = "projectile", it2 = "metal", x = data.player.x,
			y = data.player.y, hand = "", in_motion = true, angle = 0, offsetX = 0, offsetY = 0,
			image = bullet_img, destX = x, destY = y, damage = gun.damage}



		spawn_item(Bullet,local_map.items)
		TEsound.play(gunshot_aud, "gunshot_aud")

		data.player.bullets = data.player.bullets - gun.ammo_req

		TEsound.play(bullet_casing_fall_aud, "bullet_casing_fall_aud")
		p_finished_turn()

	else
		printc("out of ammo")

	end

end

function throw_grenade(x,y, grenade, hand)

	local ds = ""
	local ens = ""
	local es = ""
	local es2 = ""
	local es3 = ""

	grenade_thrown = grenade
	gren_thrown_x = x
	gren_thrown_y = y

	grenade_canvas(grenade)

	for i = 1, #local_map.enemies do

		--print("enemies x ", local_map.enemies[i].x,
		--	"enemies y ", local_map.enemies[i].y)

		--print("grenade radius ", grenade.radius)

		if local_map.enemies[i].x ~= nil and local_map.enemies[i].y ~= nil then
			if local_map.enemies[i].x <= x+grenade.radius*tile_size
				and local_map.enemies[i].y <= y+grenade.radius*tile_size
				and local_map.enemies[i].x >= x-grenade.radius*tile_size
				and local_map.enemies[i].y >= y-grenade.radius*tile_size then

				local_map.enemies[i].health = local_map.enemies[i].health - grenade.damage

				ds = grenade.damage .. ""
				ns = local_map.enemies[i].name
				es = append_strings("You hit ", ens)
				es2 = append_strings(" for ", ds)
				es3 = append_strings(es, es2)

				print("hit ", ens, " for ", ds, " enemy health : ", local_map.enemies[i].health)

				printc(es3)

			end

		end
	end

	if data.player.x <= x+grenade.radius*tile_size
				and data.player.y <= y+grenade.radius*tile_size
				and data.player.x >= x-grenade.radius*tile_size
				and data.player.y >= y-grenade.radius*tile_size then

				local pd = grenade.damage*0.75

				print ("hit yourself for ", pd)

				data.player.health = data.player.health-pd

	end

	if hand == "right" then
		table.remove(data.player.right_hand, 1)
	elseif hand == "left" then
		table.remove(data.player.left_hand, 1)
	end
	draw_gren = true
	spawn_crater(x, y)
	TEsound.play(gren_exp_aud, "gren_exp")
	p_finished_turn()


end

function draw_grenade(x, y, grenade)

	--local g_c = 0
	local fps = love.timer.getFPS()

	local g_dt = 3 * fps




	if draw_gren == true then
		--g_c = g_c+1

		for i = 1, g_dt do
			--print("displaying canvas at", x, y)

			love.graphics.draw(grenade_exp, x-((grenade.radius*tile_size)/2), y-((grenade.radius*tile_size)/2))
			--love.graphics.draw(explode_img, x, y)

		end
		draw_gren = false


	end


end

function grenade_canvas(grenade)

	grenade_exp = love.graphics.newCanvas((1+grenade.radius)*tile_size, (1+grenade.radius)*tile_size)
	local width = grenade_exp:getWidth()/tile_size
	local height = grenade_exp:getHeight()/tile_size

	local sW = width*tile_size
	local sH = height*tile_size

	sW = explode_img:getWidth()/sW
	sH = explode_img:getHeight()/sH


	love.graphics.setCanvas(grenade_exp)
	love.graphics.scale(sW, sH)
	print("drawing canvas")


			love.graphics.draw(explode_img, 0-explode_img:getWidth()/2,
				0-explode_img:getWidth()/2)



	love.graphics.scale(1,1)
	love.graphics.setCanvas()


end


function ai_projectiles()

	if local_map.enemies ~= nil then
		if local_map.items ~= nil then
			for i = 1, #local_map.enemies do
				for j = #local_map.items, 1, -1 do

					if local_map.items[j].it == "projectile" then

						if local_map.items[j].x == local_map.enemies[i].x
							and local_map.items[j].y == local_map.enemies[i].y then

							p_damage_enemy(local_map.enemies[i], local_map.items[j].damage)
							table.remove(local_map.items, j)

						end


					end

				end
			end
		end
	end
end

function move_projectiles()

	local absDistX = 0
	local absDistY = 0
	local distX = 0
	local distY = 0
	local dX = 0
	local dY = 0


	if local_map.items ~= nil then
		for i = #local_map.items, 1, -1 do

			if local_map.items[i] ~= nil then

				if local_map.items[i].it == "projectile" then

					if local_map.items[i].in_motion == true then
						if local_map.items[i].speed ~= nil and local_map.items[i].speed_mod ~= nil then
							--for j = 1, local_map.items[i].speed*local_map.items[i].speed_mod do
								if local_map.items[i].destX ~= nil then
									if local_map.items[i].destY ~= nil then
										distX, distY = map_distance_t(local_map.items[i].x,local_map.items[i].y,local_map.items[i].destX, local_map.items[i].destY)
										if distX == 0 and distY == 0 then
											table.remove(local_map.items, i)
										else
											for j = 1, local_map.items[i].speed*local_map.items[i].speed_mod do

												if distX > 0 and distY > 0 then

													local_map.items[i].angle = (math.pi*5)/4
													local_map.items[i].offsetX = tile_size
													local_map.items[i].x = local_map.items[i].x - tile_size/4
													local_map.items[i].y = local_map.items[i].y - tile_size/4
												elseif distX < 0 and distY > 0 then
													local_map.items[i].angle = (math.pi*7)/4


													local_map.items[i].x = local_map.items[i].x + tile_size/4
													local_map.items[i].y = local_map.items[i].y - tile_size/4
												elseif distX > 0 and distY < 0 then
													local_map.items[i].angle = (math.pi*3)/4
													local_map.items[i].offsetX = tile_size
													local_map.items[i].x = local_map.items[i].x - tile_size/4
													local_map.items[i].y = local_map.items[i].y + tile_size/4
												elseif distX < 0 and distY < 0 then
													local_map.items[i].angle = math.pi/4

													local_map.items[i].x = local_map.items[i].x + tile_size/4
													local_map.items[i].y = local_map.items[i].y + tile_size/4
												elseif distX == 0 and distY > 0 then
													local_map.items[i].angle = (math.pi*3)/2
													--local_map.items[i].offsetX = -tile_size
													--local_map.items[i].offsetY = tile_size
													local_map.items[i].y = local_map.items[i].y - tile_size/4
												elseif distX == 0 and distY < 0 then
													local_map.items[i].angle = math.pi/2
													local_map.items[i].offsetX = tile_size
													local_map.items[i].offsetY = tile_size
													local_map.items[i].y = local_map.items[i].y + tile_size/4
												elseif distX > 0 and distY == 0 then

													local_map.items[i].offsetX = 0
													local_map.items[i].offsetY = tile_size
													local_map.items[i].angle = math.pi
													local_map.items[i].x = local_map.items[i].x - tile_size/4
												elseif distX < 0 and distY == 0 then

													local_map.items[i].angle = 0
													local_map.items[i].x = local_map.items[i].x + tile_size/4
												end
											end


										end

									end
								end
							--end
						end
					end

				end
			end

		end

	end


end

function tree_spawn(x,y, items)

	local s_c = RNG:random(1000)

	if s_c > 900 then
		spawn_random_junk(x,y, items)
	end

end


function spawn_item(item, items)
	table.insert(items,item)
end

function spawn_seed_bag(x,y)

	SeedBag = { x = x, y = y, it = "seedbag", it2 = "seedbag", name = "seed bag",
		amount = RNG:random(10, 20), value = amount, image = seed_img,
		destX = 0, destY = 0, in_motion = false,  explored = false}

	table.insert(local_map.items, SeedBag)


end

function spawn_random_junk(x,y, items)
	junk_name = { "scrap","pipe","toaster",
		"fische tape", "spoon", "bowl",
		"watch" }
	junk_adj = { "clean", "resin-coated", "mildly-used",
		"sparkling", "greasy" }
	junk_mat = {"copper", "glass", "brass", "titanium",
		"diamond", "silver", "steel"}

	jn_value = { 3, 4, 6,
		15, 1, 20, 50 }
	ja_value = { 10, 2, 7,
		15, 8 }
	jm_value = { 4, 6, 3, 12,
		20, 10, 5 }

	local jnr = RNG:random(7)
	local jar = RNG:random(5)
	local jmr = RNG:random(7)

	local jn = junk_name[jnr]
	local ja = junk_adj[jar]
	local jm = junk_mat[jmr]

	local jname = ja .. " " .. jm .. " " .. jn

	local jvalue = jn_value[jnr] + ja_value[jar] + jm_value[jmr]


	Junk = { x = x, y = y, jn = jn, ja = ja, jm = jm,
		name = jname, value = jvalue, type = "junk", damage = 5,
		carried = false, vel = tile_size, in_motion = false,
		turn = false, equipped = false, alive = true,
		dir = "none", portaled = false, it = "junk", it2 = "metal",
		image = junk_img, hand = "none", explored = false}

	spawn_item(Junk, items)


end

function spawn_consumable()



end

function spawn_ammo(x, y)

	local r = RNG:random(1000)

	if r > 750 then

		Grenade = { name = "grenade", desc="for boom",
		value = 5, it = "grenade", it2 = "metal", x = 0, y = 0, hand = "none",
		image = grenade_img, damage = 20, radius = 0, explored = false }
		print("spawning grenade")
		Grenade.x = x
		Grenade.y = y
		print("randomizing grenade")
		Grenade = generate_random_grenade(Grenade)
		print("Grenade stats: ", "radius : ", Grenade.radius, " damage : ", Grenade.damage,
			" name : ", Grenade.name)
		spawn_item(Grenade, local_map.items)

	elseif r < 756 and r > 500 then

		BulletPack = { name = "bullet pack", desc="ammo",
			amount = RNG:random(10), x = 0, y = 0, value = 0, image = bullet_pack_img,
			explored = false, it = "bullets", it2 = "metal" }

		BulletPack.x = x
		BulletPack.y = y
		BulletPack.value = BulletPack.amount

		spawn_item(BulletPack, local_map.items)

	end


end

function spawn_hatchet(x,y)


	Hatchet = { name = "hatchet", desc="for overgrowth",
		value = 1, it = "melee", it2 = "metal", x = x, y = y, hand = "left",
		image = axe_img	, uses = RNG:random(10, 20), explored = false	}
	spawn_item(Hatchet, local_map.items)

end

function generate_random_item(items)


end

function buy_item(item_id)

	for i = 1, #maps.town.npcs do
		if maps.town.npcs[i].shopping == true then
			if buy_possible(maps.town.npcs[i].inventory[item_id].value,
				maps.town.npcs[i].price_mod) then

				table.insert(data.player.inventory,
					maps.town.npcs[i].inventory[item_id])
				print(table.tostring(data.player.inventory))
				trade_window(trade_win,maps.town.npcs[i].inventory,maps.town.npcs[i].price_mod)
				price = maps.town.npcs[i].inventory[item_id].value * maps.town.npcs[i].price_mod
				data.player.seeds = data.player.seeds - price
				table.remove(maps.town.npcs[i].inventory, item_id)

			else
				printc("Not enough seeds!")
			end

		end
	end

end

function sell_items(itemid, modifier, hand)

	if hand == "right" and sale_possible(data.player.right_hand[1].it,
		data.player.right_hand[1].it2,
		data.player.merchant_id) then

		print("merch id: ", data.player.merchant_id)
		table.insert(maps.town.npcs[data.player.merchant_id].inventory,
			data.player.right_hand[1])
		printc("sold ", data.player.right_hand[1].name, " to ",
			maps.town.npcs[data.player.merchant_id].name)
		data.player.seeds = data.player.seeds + data.player.right_hand[1].value*modifier
		table.remove(data.player.right_hand, 1)



	elseif hand == "left" and sale_possible(data.player.left_hand[1].it,
		data.player.left_hand[1].it2,
		data.player.merchant_id) then

		print("merch id: ", data.player.merchant_id)
		table.insert(maps.town.npcs[data.player.merchant_id].inventory,
			data.player.left_hand[1])
		printc("sold ", data.player.left_hand[1].name, " to ",
			maps.town.npcs[data.player.merchant_id].name)
		data.player.seeds = data.player.seeds + data.player.left_hand[1].value*modifier
		table.remove(data.player.left_hand, 1)



	end

end

function sale_possible(it, it2, merchant_id)

	if merchant_id == 2 then -- botanist possible items
		if it == "fruit" or it2 == "fruit" then return true end
		if it == "plant" or it2 == "plant" then return true end
	elseif merchant_id == 3 then -- arms possible items
		if it == "thrown" or it2 == "thrown" then return true end
		if it == "metal" or it2 == "metal" then return true end
	end

end

function buy_possible(value, price_mod)

	if data.player.seeds >= value*price_mod then
		return true
	else
		return false
	end

end

function draw_items()

	if #data.player.local_map.items ~= nil then
		for i = 1, #data.player.local_map.items do
			--love.graphics.draw(data.player.local_map.items[i].image,
			--	data.player.local_map.items[i].x,
			--	data.player.local_map.items[i].y)
			draw_in_fov(data.player.local_map.items[i])

		end
	end

end

function veggie_generator(x, y)

	-- tomato, carrot, strawberry, watermelon, cherry, pear, broccoli
	-- potato, eggplant, radish, corn

	veggie_name = { "tomato", "carrot", "strawberry", "watermelon",
		"cherry", "pear", "broccoli", "potato", "eggplant", "radish",
		"corn" }

	veggie_state = { "ripe ", "rotted ", "fresh ", "fermenting ",
		"diseased ", "infested " }

	veggie_img = { tomato_img, carrot_img, strawberry_img,
		watermelon_img, cherry_img, pear_img, broccoli_img,
		potato_img, eggplant_img, radish_img, corn_img }

	v_p1 = { 10, 7, 3, 14, 6, 8, 11, 12, 17, 5, 9 }
	v_p2 = { 2, 0.2, 3, 0.5, 0.1, 0.05 }



	local r1 = RNG:random(11)
	local r2 = RNG:random(6)

	local vn = veggie_name[r1]
	local vs = veggie_state[r2]

	local vg = append_strings(vs, vn)

	local vv = v_p1[r1]*v_p2[r2]

	Veggie = { name = vg, x = x, y = y, image = veggie_img[r1],
		it = vn, it2 = "plant", hand = "none", value = vv,
		explored = false }

	print("spawning ", Veggie.name)

	spawn_item(Veggie, local_map.items)

end

function veggie_selector()

	veggie_name = { "tomato", "carrot", "strawberry", "watermelon",
		"cherry", "pear", "broccoli", "potato", "eggplant", "radish",
		"corn" }

	veggie_state = { "ripe ", "rotted ", "fresh ", "fermenting ",
		"diseased ", "infested " }

	local r1 = RNG:random(11)
	local r2 = RNG:random(6)

	local vn = veggie_name[r1]
	local vs = veggie_state[r2]

	local vg = append_strings(vs, vn)


	return vg

end

